# Locate NetCore library
#
# Will define:
# ${NETCORE_LIBRARIES} for use with TARGET_LINK_LIBRARIES()
# ${NETCORE_INCLUDE_DIRECTORIES} for use with INCLUDE_DIRECTORIES()

INCLUDE(netsetgo_common)

# note that for now, we are assuming that building on Apple means building for iOS
IF (APPLE)
  SET(BUILD_NETCORE_IOS YES)
ELSE (APPLE)
  SET(BUILD_NETCORE_IOS NO)
ENDIF (APPLE)
 
# variable names of the individual NetSetGo libraries.  Can be used in application cmakelist.txt files.
IF (BUILD_NETCORE_IOS)
  FIND_NETSETGO_IOS_LIBRARIES(NETCORE_LIBRARY NetCore)

  SET(NETCORE_LIBRARY       ${NETCORE_LIBRARY_IPHONEOS})
  SET(NETCORE_DEBUG_LIBRARY ${NETCORE_DEBUG_LIBRARY_IPHONEOS})
ELSE (BUILD_NETCORE_IOS)
  FIND_NETSETGO_LIBRARY(NETCORE_LIBRARY       NetCore)
  FIND_NETSETGO_LIBRARY(NETCORE_DEBUG_LIBRARY NetCoreD)
ENDIF (BUILD_NETCORE_IOS)

IF (NOT NETCORE_DEBUG_LIBRARY)
  SET(NETCORE_DEBUG_LIBRARY ${NETCORE_LIBRARY})
  MESSAGE(STATUS "No debug library was found for NETCORE_DEBUG_LIBRARY")
  MESSAGE(STATUS "Now set to ${NETCORE_DEBUG_LIBRARY}")
ENDIF()

# convienent list of libraries to link with when using NetCore
IF (BUILD_NETCORE_IOS)
  SET(LOCAL_LIB_PREFIX  lib)
  SET(LOCAL_LIB_POSTFIX .a)
  SET(NETCORE_LIBRARIES
    ${LOCAL_LIB_PREFIX}NetCore${LOCAL_LIB_POSTFIX}
  )
ELSE (BUILD_NETCORE_IOS)
  SET(NETCORE_LIBRARIES
      optimized ${NETCORE_LIBRARY} debug ${NETCORE_DEBUG_LIBRARY}
  )
ENDIF (BUILD_NETCORE_IOS)

SET(NETCORE_INCLUDE_DIRECTORIES ${NETSETGO_INCLUDE_DIR})

# handle the QUIETLY and REQUIRED arguments and set NETCORE_FOUND to TRUE if 
# all listed variables are TRUE
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(NetCore DEFAULT_MSG NETSETGO_INCLUDE_DIR NETCORE_LIBRARY)
